package com.airbnb.mvrx.sample.features.book.views

import android.content.Context
import android.view.View
import android.widget.FrameLayout
import com.airbnb.epoxy.ModelProp
import com.airbnb.epoxy.ModelView
import com.airbnb.epoxy.TypedEpoxyController
import com.example.mvrxstudy.R
import com.yt.ytdeep.client.dto.BookDTO

@ModelView(autoLayout = ModelView.Size.MATCH_WIDTH_WRAP_HEIGHT)
class BDRecommendBook @JvmOverloads constructor(context: Context) : FrameLayout(context) {

    private val mRvList: GridEpoxyRecyclerView
    private val mController: RecommendBookController

    init {
        View.inflate(context, R.layout.view_book_recommend, this)
        mRvList = findViewById(R.id.rv_list)
        mController = RecommendBookController()
        mRvList.setController(mController)
    }

    @ModelProp
    fun setList(list: List<BookDTO>) {
        mController.setData(list)
    }

    class RecommendBookController : TypedEpoxyController<List<BookDTO>>() {
        override fun buildModels(data: List<BookDTO>?) {
            data?.forEach { each ->
                bDRecommendBookItem {
                    id(each.id)
                    image(each.thumbnails)
                    title(each.name)
                }
            }
        }

    }

}